package com.sskjdata.cg.dto;


import com.fasterxml.jackson.annotation.JsonInclude;
import com.sskjdata.cg.exception.IntelligentException;
import lombok.Data;

import java.io.Serializable;

/**
 * 响应数据
 */
@JsonInclude(JsonInclude.Include.NON_NULL)
@Data
public class ResponseData implements Serializable{
    private String code;//状态码
    private String msg;//消息
    private Object data;//数据

    public ResponseData(ResponseCodeEnum responseCodeEnum, Object data) {
        this.code = responseCodeEnum.getCode();
        this.msg = responseCodeEnum.getMsg();
        this.data = data;
    }


    public ResponseData(ResponseCodeEnum responseCodeEnum) {
        this.code = responseCodeEnum.getCode();
        this.msg = responseCodeEnum.getMsg();
    }
    public ResponseData(IntelligentException exception) {
        if(exception.getResponseCodeEnum()!=null){
            this.code = exception.getResponseCodeEnum().getCode();
            this.msg = exception.getResponseCodeEnum().getMsg();
        }else{
            this.code =ResponseCodeEnum.ERROR.getCode();
            this.msg = exception.getMessage();
        }
    }
}
